import java.util.Stack;

public class Test07 {
    public static class Myqueue<T>{
        private Stack<T> stack1 = new Stack<>();//放入
        private Stack<T> stack2 = new Stack<>();//弹出

        public Myqueue() {
        }

        //添加
        public void add(T t){
            stack1.add(t);
        }

        //删除操作
        public T delete(){
            if (stack2.isEmpty()){
                while(!stack1.isEmpty()){
                    stack2.add(stack1.pop());
                }
            }
            // 如果弹出栈中还没有数据就抛出异常
            if (stack2.isEmpty()) {
                throw new RuntimeException("No more element.");
            }
            return stack2.pop();
        }

        //查看头
        public T peek(){
            if (stack2.isEmpty()){
                while(!stack1.isEmpty()){
                    stack2.add(stack1.pop());
                }
            }
            // 如果弹出栈中还没有数据就抛出异常
            if (stack2.isEmpty()) {
                throw new RuntimeException("No more element.");
            }
            return stack2.peek();
        }
    }
}
